home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / oleo-1_4.lha / oleo-1.4 / panic.c < prev    next >
C/C++ Source or Header  |  1993-05-21  |  4KB  |  187 lines

  1. /*    Copyright (C) 1990, 1992, 1993 Free Software Foundation, Inc.
  2.  
  3. This file is part of Oleo, the GNU Spreadsheet.
  4.  
  5. Oleo is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. Oleo is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with Oleo; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include <stdio.h>
  20. #include "funcdef.h"
  21. #include "sysdef.h"
  22.  
  23. #include "global.h"
  24. #include "io-generic.h"
  25. #include "io-abstract.h"
  26. #include "info.h"
  27. #include "cmd.h"
  28. #include "panic.h"
  29.  
  30.  
  31. extern char **environ;
  32. /* I hope i don't need these since they aren't write for all systems. */
  33. #if 0
  34. #ifdef __STDC__
  35. extern int dup (int);
  36. extern int close (int);
  37. extern VOIDSTAR sbrk (size_t);
  38. extern VOIDSTAR brk (VOIDSTAR);
  39. #else
  40. extern int dup ();
  41. extern int close ();
  42. extern VOIDSTAR sbrk ();
  43. extern VOIDSTAR brk ();
  44. #endif
  45. #endif
  46.  
  47.  
  48.  
  49. #ifdef __STDC__
  50. void
  51. panic_write_file (FILE *fp, struct rng *rng)
  52. #else
  53. void
  54. panic_write_file (fp, rng)
  55.      FILE *fp;
  56.      struct rng *rng;
  57. #endif
  58. {
  59. #ifdef atarist
  60.   io_error_msg ("panic save format not implemented");
  61. #else
  62.   int fd;
  63.   VOIDSTAR datend;
  64.   VOIDSTAR datstart;
  65.   unsigned long cnt;
  66.  
  67.   if (rng)
  68.     {
  69.       io_error_msg ("Can't write partial panic-save files");
  70.       return;
  71.     }
  72.   fd = dup (fileno (fp));
  73.   if (fd < 0)
  74.     {
  75.       io_error_msg ("Couldn't dup save file");
  76.       return;
  77.     }
  78.   datstart = (VOIDSTAR) (&environ + sizeof (char **));
  79.   datend = (VOIDSTAR) sbrk (0);
  80.   if (datend == (char *) -1)
  81.     {
  82.       io_error_msg ("Couldn't sbrk(0)!");
  83.       close (fd);
  84.       return;
  85.     }
  86.  
  87.   cnt = (char *) datend - (char *) datstart;
  88.   if (write (fd, &cnt, sizeof (cnt)) != sizeof (cnt))
  89.     {
  90.       io_error_msg ("Couldn't write %lu (%d bytes) to save file",
  91.             cnt, sizeof (cnt));
  92.       close (fd);
  93.       return;
  94.     }
  95.   if (write (fd, datstart, cnt) != cnt)
  96.     {
  97.       io_error_msg ("Couldn't write %lu bytes to save file", cnt);
  98.       close (fd);
  99.       return;
  100.     }
  101.   if (close (fd) < 0)
  102.     {
  103.       io_error_msg ("Couldn't close save file");
  104.       return;
  105.     }
  106.  
  107. #endif
  108. }
  109.  
  110. #ifdef __STDC__
  111. void
  112. panic_read_file (FILE *fp, int ismerge)
  113. #else
  114. void
  115. panic_read_file (fp, ismerge)
  116.      FILE *fp;
  117.      int ismerge;
  118. #endif
  119. {
  120. #ifdef atarist
  121.   io_error_msg ("panic save format not implemented");
  122. #else
  123.   int fd;
  124.   unsigned long cnt;
  125.   VOIDSTAR datstart;
  126.  
  127.   if (ismerge)
  128.     {
  129.       io_error_msg ("Can't merge panic-save files");
  130.       return;
  131.     }
  132.   if ((fd = dup (fileno (fp))) < 0)
  133.     {
  134.       io_error_msg ("Couldn't dup save file");
  135.       return;
  136.     }
  137.   if (read (fd, (VOIDSTAR) & cnt, sizeof (cnt)) != sizeof (cnt))
  138.     {
  139.       io_error_msg ("Couldn't read data_size (%d bytes) from save file", sizeof (cnt));
  140.       close (fd);
  141.       return;
  142.     }
  143.   datstart = (VOIDSTAR) (&environ + sizeof (char **));
  144.   if ((VOIDSTAR)brk ((char *) datstart + cnt) == (VOIDSTAR) - 1)
  145.     {
  146.       io_error_msg ("Couldn't allocate %lu bytes of memory", cnt);
  147.       close (fd);
  148.       return;
  149.     }
  150.   if (read (fd, datstart, cnt) != cnt)
  151.     {
  152.       io_error_msg ("Couldn't read in %lu bytes of data", cnt);
  153.       close (fd);
  154.       return;
  155.     }
  156.   if (close (fd) < 0)
  157.     io_error_msg ("Couldn't close save file");
  158.   io_recenter_all_win ();
  159. #endif
  160. }
  161.  
  162. #ifdef __STDC__
  163. int
  164. panic_set_options (int set_opt, char *option)
  165. #else
  166. int
  167. panic_set_options (set_opt, option)
  168.      int set_opt;
  169.      char *option;
  170. #endif
  171. {
  172.   return -1;
  173. }
  174.  
  175.  
  176. #ifdef __STDC__
  177. void
  178. panic_show_options (void)
  179. #else
  180. void
  181. panic_show_options ()
  182. #endif
  183. {
  184.   io_text_line
  185.     ("File format:  panic save   (quick-n-dirty data-segment dump)");
  186. }
  187.